import { StructDto } from './dto/struct.dto';
import { CreateStructDto } from './dto/create.struct.dto';
import adminConfig from '@src/config/admin.config';
import { Controller, Post, HttpCode, HttpStatus, Body, Get, Param, Delete, Patch, Query, ParseIntPipe, HttpException, Req } from '@nestjs/common';
import { ApiOperation, ApiCreatedResponse, ApiOkResponse, ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { StructService } from '@src/service/admin/struct/struct.service';
import { StructRep } from './dto';
import { ObjectType } from '@src/types';

@ApiTags('api-struct')
@ApiBearerAuth()
@Controller(`${adminConfig.adminPath}/struct`)
export class StructController {
  constructor(
    private readonly structService: StructService
  ) { }

  /**
 * @Description: 获取全部的组织机构
 * @param {type}
 * @return:
 */
  @ApiOperation({ summary: '组织结构列表', description: '获取组织机构列表' })
  @ApiOkResponse({ type: [StructRep] })
  @Get('list')
  @HttpCode(HttpStatus.OK)
  async userList(@Query() queryOption: ObjectType): Promise<StructRep[]> {
    return await this.structService.findPage(queryOption);
  }

  /**
* @Description: 创建组织机构
* @param {type}
* @return:
*/
  @ApiOperation({ summary: '创建组织机构', description: '创建组织机构' })
  @ApiCreatedResponse({
    type: CreateStructDto,
    description: '创建用户DTO',
  })
  @ApiOkResponse({ type: StructRep })
  @Post('create')
  @HttpCode(HttpStatus.CREATED)
  public async createStruct(@Body() createStructDto: CreateStructDto): Promise<StructRep> {
    const struct = await this.structService.create(createStructDto);
    return struct
  }
}